package cn.edu.scau.cmi.liqiquan.sameComponent;

import java.util.ArrayList;

public class Composite implements Component{
	private String name;
	private ArrayList<Composite> folders = new ArrayList<Composite>();
	private ArrayList<Leaf> files = new ArrayList<Leaf>();
	
	public Composite(String name) {
		this.name = name;
	}
	
	public String getName() {
		return this.name + "/";
	}
	
	@Override
	public void addFolder(Composite c) {
		this.folders.add(c);
	}
	
	@Override
	public void addFile(Leaf c) {
		this.files.add(c);
	}
	
	@Override
	public String scan() {
		String str = "";
		for(Composite folder: folders) {
			str += folder.getName();
			str += folder.scan();
		}
		str += "\n";
		for(Leaf file: files) {
			str += file.scan();
		}
		
		return str;
	}
}
